Ext.ns('journal.home');

// {{{
journal.home.EntryExplorerToolbar = Ext.extend(Ext.Toolbar, (function() {

    return {

        // configurables
        // anything what is here can be configured from outside

        // {{{
        initComponent : function() {

            // hard coded config - cannot be changed from outside
            var config = {
                height : 27,
                width : '100%',
                items : [ 'Filter:', {
                    xtype : 'trigger',
                    triggerClass : 'x-form-clear-trigger',
                    onTriggerClick : function() {
                        this.setValue('');
                        journal.home.EntryExplorerPanel.filter.clear();
                    },
                    id : 'filter',
                    enableKeyEvents : true,
                    listeners : {
                        focus : function() {
                            journal.home.Main.explorerPanel.activeTab.treeEditor.cancelEdit();
                        },
                        keyup : {
                            buffer : 1000,
                            fn : function(field, e) {
                                if (Ext.EventObject.ESC == e.getKey()) {
                                    field.onTriggerClick();
                                } else {
                                    journal.StateService.restoreFlag = true;
                                    var val = this.getRawValue();
                                    var re = new RegExp('.*' + val + '.*', 'i');
                                    journal.home.EntryExplorerPanel.filter.clear();
                                    journal.home.EntryExplorerPanel.filter.filter(re, 'text');
                                }
                            }
                        }
                    }
                },

                {
                    xtype : 'tbfill'
                }, {
                    id : 'tbbRefreshTree',
                    xtype : 'tbbutton',
                    tooltip : 'Refresh/Reset Tree',
                    iconCls : 'icon-synchronize'
                }, {
                    xtype : 'tbbutton',
                    tooltip : 'Prevent Drag/Drop',
                    iconCls : 'icon-lock',
                    enableToggle : true,
                    pressed : true,
                    handler : function(btn, e) {
                        if (btn.pressed) {
                            btn.ownerCt.ownerCt.dragZone.lock();
                        } else {
                            btn.ownerCt.ownerCt.dragZone.unlock();
                        }
                    }
                }, {
                    id : 'ce-linkweditor',
                    xtype : 'tbbutton',
                    tooltip : 'Link with Editor',
                    iconCls : 'icon-connect',
                    enableToggle : true,
                    pressed : true,
                    handler : function(btn, e) {
                        linkWithEditor = btn.pressed;
                        var tp = Ext.getCmp(journal.Constant.Id.EDITORPANEL);
                        tp.fireEvent('tabchange', tp, tp.getActiveTab());
                    }
                }, {
                    id : journal.home.EntryExplorerToolbar.ButtonId.CollapseAll,
                    hidden : true,
                    xtype : 'tbbutton',
                    tooltip : 'Collapse All',
                    iconCls : 'icon-collapseAll',
                    disabled : true,
                    handler : function() {
                        var tree = Ext.getCmp(journal.Constant.Id.ENTRY_TREE);
                        tree.collapseAll();
                        var root = tree.getRootNode();
                        root.expand();
                    }
                }, {
                    id : journal.home.EntryExplorerToolbar.ButtonId.ExpandAll,
                    hidden : true,
                    xtype : 'tbbutton',
                    iconCls : 'icon-expandAll',
                    disabled : true,
                    tooltip : 'Expand All',
                    handler : function() {
                        Ext.getCmp(journal.Constant.Id.ENTRY_TREE).expandAll();
                    }
                } ]
            };// var config

            // apply config
            Ext.apply(this, Ext.apply(this.initialConfig, config));

            // call parent
            journal.home.EntryExplorerToolbar.superclass.initComponent.apply(this, arguments);

        } // e/o function initComponent
    // }}}
    };
})()); // e/o extend

journal.home.EntryExplorerToolbar.ButtonId = {
    CollapseAll : 'EntryExplorerToolbar.CollapseAll',
    ExpandAll : 'EntryExplorerToolbar.ExpandAll'
};

// register xtype
Ext.reg('journal.home.EntryExplorerToolbar', journal.home.EntryExplorerToolbar);
// }}}
